Reversing a string without using any built in function in JavaScript